package com.shujia.java.day21.demo2;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description: Demo6 邮箱验证
 * @Author: 王火火
 * @Date: 2019/8/24 16:01
 *
 *  xxxxxxxxxxxxx@qq.com
 *  yyyyxxxxxxxxx@163.com
 *  Yyyyxxxxxxxxxx@163.com
 *  Yyyyxxxxxxxxxx@qq.pp.com
 *  xxxxxxxxxxxxxx@qq.pp.com.cn
 */

public class Demo6 {
    public static void main(String[] args) {
        //要验证的只有数字的邮箱
//        String email ="1219446210@qq.com";
//        //格式
//        String pattern="^[0-9]{5,12}@[q]{2}\\.[a-z]{3}$";
        //要验证有数字有小写字母的邮箱
//        String email = "chen1219446210@qq.com";
//        //格式
//        String pattern="^[a-z]{0,}[0-9]{5,12}@[q]{2}\\.[a-z]{3}$";
//        //验证的是首字母大写的邮箱
//        String email = "Chen1219446210@qq.com";
//        //格式
//        String pattern="^[A-Z][a-z]{0,}[0-9]{5,12}@[a-z]{2}\\.[a-z]{3}$";
        //多个后缀
        String email = "1219446210@qq.com.cn";
        //格式
        //String pattern="^[0-9]{5,12}@[a-z]{2,3}[.][a-z]{2,3}[.][a-z]{2,3}$";
        String pattern="^[0-9]{5,12}@[a-z]{2,3}([.][a-z]{2,3}){2}$";
        //转化格式
        Pattern compile = Pattern.compile(pattern);
        //进行匹配
        Matcher matcher = compile.matcher(email);
        //输出结果
        System.out.println(matcher.matches());
    }
}
